import request from '@/utils/request'

export const SystemMangeAPI = {
  ListMyProjects(data) {//我的项目
    return request({
      url: 'project/ListMyProjects',
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  CreateProject(data) {//新增项目
    return request({
      url: 'project/CreateProject',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  UpdateProject(data) {//更新项目
    return request({
      url: 'project/UpdateProject',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  deleteProjectAPI({ userid, id }) {//删除项目
    return request({
      url: `project/RemoveProjectUser?ID=${id}&USER_ID=${userid}`,
      method: 'GET',
      headers: {
        'Content-Type': 'application/json'
      },
    })
  },
  CreateShareAPI(data) {//分享
    return request({
      url: `share/CreateShare`,
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data
    })
  },
  getShareAPI(data) {//分享
    return request({
      url: `/share/GetShare/${data.key}?password=${data.password}`,
      method: 'GET',
      headers: {
        'Content-Type': 'application/json'
      },
      data
    })
  },
  deleteResource(id) {//删除资源组
    return request({
      url: `resource/DeleteResource?ID=${id}`,
      method: 'GET',
      headers: {
        'Content-Type': 'application/json'
      },
    })
  },
  ListResourceItemByProject(data) {//获取项目所有资源
    return request({
      url: 'resource/ListResourceItemByProject?projectId=' + data.projectId,
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  UpdateResourceItem(data) {
    return request({
      url: 'resourceItem/Update',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  ListByResource(data) {//根据项目查资源组
    return request({
      url: 'resource/ListResources?projectId=' + data.projectId,
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },

  CreateResource(data) {//创建资源
    return request({
      url: 'resource/CreateResource',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  UpdateResource(data) {//更新资源
    return request({
      url: 'resource/UpdateResource',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  UploadFiles(data) {//上传资源
    return request({
      url: 'resourceItem/UploadFiles',
      method: 'post',
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      data: data
    })
  },
  ziyuanCreate(data) {//新增资源明细
    return request({
      url: 'resourceItem/Create',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  ziyuanUpdate(data) {//更新资源明细
    return request({
      url: 'resourceItem/Update',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  generateHLS(data) {//视频转码
    return request({
      url: 'resource/generateHLS?resourceId=' + data.resourceId,
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  startCut(data) {//启动切片
    return request({
      url: 'video/startCut?resourceId=' + data.resourceId,
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  startRecording(data) {//启动录播
    return request({
      url: 'recording/StartRecording?resourceId=' + data.resourceId,
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  endCut(data) {//结束切片
    return request({
      url: 'video/StopCut?resourceId=' + data.resourceId,
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  endRecording(data) {//结束录播
    return request({
      url: 'recording/StopRecording?resourceId=' + data.resourceId,
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  ListFiles(data) {//云盘文件列表
    return request({
      url: 'yunDisk/ListFiles?projectId=' + data.projectId + '&parentId=' + data.parentId,
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  uploadFile(data) {//云盘文件列表
    return request({
      url: '/upload',
      method: 'post',
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      data: data
    })
  },
  CreateFolder(data) {//云盘创建目录
    return request({
      url: 'yunDisk/CreateFolder',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  DeleteFile(data) {//云盘文件列表新增
    return request({
      url: 'yunDisk/DeleteFile?ID=' + data.ID,
      method: 'get',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },
  UpdateFile(data) {//云盘文件更新
    return request({
      url: 'yunDisk/UpdateFile',
      method: 'post',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data
    })
  },

  yunpanUpload(data) {//上传资源
    return request({
      url: 'yunDisk/Upload',
      method: 'post',
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      data: data
    })
  },


  /**
   * 下载模版
   * @param data: {}
   * @returns {AxiosPromise}
   */
  otherdownload(data) {
    return request({
      url: `/index/export`,
      method: 'POST',
      // header: {
      //   headers: { 'Content-Type': 'application/x-download' }
      // },
      responseType: 'blob',
      data: data,
    }).then((res) => {
      console.log(res)
      const link = document.createElement('a')
      let blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
      link.style.display = 'none'
      // link.href = URL.createObjectURL(blob)
      console.log('-----')
      window.open(URL.createObjectURL(blob));
      // link.download = res.headers['content-disposition'] //下载后文件名
      // link.download = data.fileName //下载的文件名
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    })

  },


}

